/********************************************************************************
 * Project Name		[JavaEE_Web]
 * File Name     	[NoCacheFilter.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package filter.cases;

import java.io.IOException;

import javax.servlet.DispatcherType;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import filter.HttpFilter;

/**
 * 无缓存过滤器
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
@WebFilter(filterName = "NoCacheFilter", urlPatterns = "*.jsp", dispatcherTypes = { DispatcherType.REQUEST,
		DispatcherType.INCLUDE, DispatcherType.FORWARD, DispatcherType.ERROR })
public class NoCacheFilter extends HttpFilter {

	@Override
	public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
			throws IOException, ServletException {
		response.setDateHeader("Expires", -1);
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");

		filterChain.doFilter(request, response);
	}
}
